package com.crazy.practice.boot.controller;

import cn.hutool.aop.ProxyUtil;
import com.crazy.practice.boot.service.UserService;
import com.crazy.practice.boot.service.impl.UserServiceImpl;
import com.crazy.practice.model.AverageUser;
import com.crazy.proxy.CglibProxy;
import com.crazy.proxy.JdkProxy;
import com.crazy.proxy.MyAspect;

import java.util.Date;

/**
 * @author panyonghui
 * @describe 测试代理
 * @date 2023/1/6 11:09
 */
public class Test {
    public static void main(String[] args) {
        UserServiceImpl userServiceImpl = new UserServiceImpl();
        // 基于jdk的动态代理（代理类需要实现接口）
        UserService userService = JdkProxy.getProxyInstance(userServiceImpl, MyAspect.class);
        System.out.println("jdk代理：" + userService.userOrderQuery(null));

        // 基于spring的cglib动态代理
        UserService userService2 = CglibProxy.getProxyInstance(userServiceImpl, MyAspect.class);
        System.out.println("cglib代理:" + userService2.userOrderQuery(null));
    }
}
